package com.klod


import com.klod.data.mapping.BannersTable
import com.klod.data.mapping.NewsTable
import com.klod.data.mapping.NewsTypeTable
import com.klod.data.mapping.UserTable
import io.ktor.http.*
import io.ktor.serialization.gson.*
import io.ktor.server.application.*
import io.ktor.server.plugins.contentnegotiation.*
import io.ktor.server.plugins.cors.routing.*
import io.ktor.server.response.*
import org.jetbrains.exposed.sql.Database
import org.jetbrains.exposed.sql.SchemaUtils
import org.jetbrains.exposed.sql.transactions.transaction

fun Application.configureDatabase() {


//    Database.init()

    val database = Database.connect(
        url = "jdbc:mysql://localhost:3306/news_db",
        driver = "com.mysql.cj.jdbc.Driver",
        user = "root",
        password = "fc25155+",

        )
    //创建表
    transaction {
        val list = listOf(NewsTable,
            NewsTypeTable,
            UserTable,
            BannersTable

        )
//        SchemaUtils.create(*list.toTypedArray())
        SchemaUtils.createMissingTablesAndColumns(*list.toTypedArray())

    }
}

